package com.wb.spring.boot.autoconfigure.register;

import com.wb.spring.boot.autoconfigure.annotation.ConditionalOnWbClientEnabled;
import com.wb.spring.boot.autoconfigure.listener.WbRegisterListener;
import com.wb.spring.boot.autoconfigure.listener.WbUnRegisterListener;
import com.wb.spring.boot.autoconfigure.load.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author sw
 * @create 2023-03-03 9:43
 */

@Slf4j
@ConditionalOnWbClientEnabled
@Configuration
@AutoConfigureAfter(value = {WbRedisRegisterAutoConfiguration.class, WbConsulRegisterAutoConfiguration.class})
public class WbRegisterAutoConfiguration {

    /**
     * 服务启动后的监听器
     *
     * @return
     */
    @Bean
    public WbRegisterListener wbRegisterListener() {
        return new WbRegisterListener();
    }

    /**
     * 服务停止的监听器
     *
     * @return
     */
    @Bean
    public WbUnRegisterListener wbUnRegisterListener() {
        return new WbUnRegisterListener();
    }


    @ConditionalOnMissingBean(Load.class)
    @ConditionalOnWbClientLoadPolling
    @Bean
    public Load pollingLoad() {
        Load load = new PollingLoad();
        return load;
    }

    @ConditionalOnMissingBean(Load.class)
    @ConditionalOnWbClientLoadRandom
    @Bean
    public Load randomLoad() {
        Load load = new RandomLoad();
        return load;
    }

    @ConditionalOnMissingBean(Load.class)
    @ConditionalOnWbClientLoadWeightPolling
    @Bean
    public Load weightPollingLoad() {
        Load load = new WeightPollingLoad();
        return load;
    }


    @ConditionalOnMissingBean(Load.class)
    @ConditionalOnWbClientLoadHash
    @Bean
    public Load hashLoad() {
        Load load = new HashLoad();
        return load;
    }

    @ConditionalOnMissingBean(Load.class)
    @ConditionalOnWbClientLoadWeightRandom
    @Bean
    public Load weightRandomLoad() {
        Load load = new WeightRandomLoad();
        return load;
    }



}
